<?php

namespace common\models\base;

use Yii;

/**
 * This is the model class for table "{{%guarantee_company_dot_site}}".
 *
 * @property int $id
 * @property int $guarantee_company_id
 * @property string $sign_code 标识码
 * @property string $name
 * @property string $bank_zoneno 业务发生地  //todo 读取部门wg_code
 * @property string $contact_mobile 联系人手机号
 * @property string $link_bairong_component_conf 使用的百融大数据组件配置
 *
 * @property CreditOrder[] $creditOrders
 * @property GuaranteeCompany $guaranteeCompany
 * @property UserGuaranteeCompanyDotSiteBind[] $userGuaranteeCompanyDotSiteBinds
 * @property User[] $users
 */
class GuaranteeCompanyDotSite extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%guarantee_company_dot_site}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['guarantee_company_id', 'sign_code', 'name'], 'required'],
            [['guarantee_company_id'], 'integer'],
            [['sign_code'], 'string', 'max' => 32],
            [['name', 'link_bairong_component_conf'], 'string', 'max' => 50],
            [['bank_zoneno'], 'string', 'max' => 4],
            [['contact_mobile'], 'string', 'max' => 11],
            [['guarantee_company_id'], 'exist', 'skipOnError' => true, 'targetClass' => GuaranteeCompany::className(), 'targetAttribute' => ['guarantee_company_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'guarantee_company_id' => Yii::t('app', 'Guarantee Company ID'),
            'sign_code' => Yii::t('app', '标识码'),
            'name' => Yii::t('app', 'Name'),
            'bank_zoneno' => Yii::t('app', '业务发生地  //todo 读取部门wg_code'),
            'contact_mobile' => Yii::t('app', '联系人手机号'),
            'link_bairong_component_conf' => Yii::t('app', '使用的百融大数据组件配置'),
        ];
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreditOrders()
    {
        return $this->hasMany(CreditOrder::className(), ['guarantee_company_dot_site_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getGuaranteeCompany()
    {
        return $this->hasOne(GuaranteeCompany::className(), ['id' => 'guarantee_company_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUserGuaranteeCompanyDotSiteBinds()
    {
        return $this->hasMany(UserGuaranteeCompanyDotSiteBind::className(), ['guarantee_company_dot_site_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getUsers()
    {
        return $this->hasMany(User::className(), ['id' => 'user_id'])->viaTable('{{%user_guarantee_company_dot_site_bind}}', ['guarantee_company_dot_site_id' => 'id']);
    }
}
